<template>
  <div>
    <van-form @submit="onSubmit">
      <!-- <van-field
        v-model="userInfo.userName"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[
          { required: true, message: '请填写用户名' },
          {
            validator: (val) => {
              if (val === '你妹的') {
                return true
              } else {
                return false
              }
            },
            message: '你妹的，你怎么不写你妹的'
          }
        ]"
      /> -->
      <van-field
        v-model="userInfo.userName"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[
          { required: true, message: '请填写用户名' }
        ]"
      />
      <van-field
        v-model="userInfo.pwd"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
    <my-tabbar />
  </div>
</template>

<script>
import { Toast } from 'vant'
import MyTabbar from '@components/MyTabbar'
export default {
  data () {
    return {
      userInfo: {
        userName: '',
        pwd: ''
      }
    }
  },
  methods: {
    onSubmit () {
      setTimeout(() => {
        // 返回用户信息以及token
        const userInfo = {
          nickName: '小明',
          avatar: 'https://dss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4065099561,1515241216&fm=26&gp=0.jpg'
        }
        const token = 'hgdiwjdw9893hfddw'
        localStorage.setItem('userInfo', JSON.stringify(userInfo))
        localStorage.setItem('access_token', token)
        // 弹出提醒 跳转页面
        Toast('登录成功')
        if (this.$route.query.from) {
          this.$router.push(this.$route.query.from)
        } else {
          this.$router.push('/home')
        }
      }, 2000)
    }
  },
  components: {
    MyTabbar
  }
}
</script>

<style lang="scss" scoped>
</style>
